/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package UserBussiness;

import DAO.UserDAO;
import Entities.User;
import Helper.Utils;

/**
 *
 * @author Administrator
 */
public class UserManager {

    public boolean isNull(String username, String password) {
        if (Utils.isNull(username) || Utils.isNull(password)) {
            return true;
        }
        return false;
    }

    public boolean isBlank(String username, String password) {
        if (Utils.isBlank(username) || Utils.isBlank(password)) {
            return true;
        }
        return false;
    }

    public boolean hasSpecialChar(String username, String password) {
        Utils u = new Utils();
        if (u.checkSpecialCharacter(username) || u.checkSpecialCharacter(password)) {
            return true;
        }
        return false;
    }

    public boolean isExistUser(String username, String password) {
        boolean exist = false;
        if (!isNull(username, password)
                && !isBlank(username, password)
                && !hasSpecialChar(username, password)) {
            UserDAO userDAO = new UserDAO();
            User user = userDAO.getUser(username, password);
            if (user != null) {
                exist = true;
            }
        }        
        return exist;
    }

    public String getPermission(String username, String password) {
        String permission = null;
        if(isExistUser(username, password))
        {
            UserDAO userDAO = new UserDAO();
            User user = userDAO.getUser(username, password);
            permission = user.getPermission();
        }
        return permission;
    }    
}
